
package com.putao.tinytime.activities.menu.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.putao.tinytime.R;
import com.putao.tinytime.bean.CollageConfigInfo;
import com.putao.tinytime.util.FileOperationHelper;
import com.putao.tinytime.util.PuTaoConstants;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by yanglun on 15/3/23.
 */
public class SampleItemInfoListAdapter extends BaseAdapter
{
    private ArrayList<CollageConfigInfo.SampleItemInfo> mList;
    private Context mContext;

    public SampleItemInfoListAdapter(Context context)
    {
        mContext = context;
    }

    @Override
    public int getCount()
    {
        if (mList == null)
        {
            return 0;
        }
        else
        {
            return mList.size();
        }
    }

    @Override
    public CollageConfigInfo.SampleItemInfo getItem(int position)
    {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return 0;
    }

    @Override
    public View getView(int position , View convertView , ViewGroup parent)
    {
        SampleItemInfoHolder holder;
        if (convertView == null)
        {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_sample_item_info_list_item, null);
            holder = new SampleItemInfoHolder();
            holder.tiny_time_sample_item_iv = (ImageView) convertView.findViewById(R.id.tiny_time_sample_item_iv);
            holder.tiny_time_sample_title_tv = (TextView) convertView.findViewById(R.id.tiny_time_sample_title_tv);
            convertView.setTag(holder);
        }
        else
        {
            holder = (SampleItemInfoHolder) convertView.getTag();
        }

        holder.tiny_time_sample_title_tv.setText(getItem(position).sample_name);


       String path = FileOperationHelper.getExternalFilePath()+ "/" + PuTaoConstants.COLLAGE_FLODER_NAME+"/"+getItem(position).sample_thumbnail ;
//        String path = WaterMarkHelper.getWaterMarkFilePath() + iconInfo.sample_image;
        //Bitmap bitmap = BitmapHelper.getInstance().loadBitmap(path);
        //holder.water_marker_item_icon_im.setImageBitmap(bitmap);
        DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.no_photo).showImageOnFail(R.drawable.no_photo)
                .cacheInMemory(true).cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565).build();
        holder.tiny_time_sample_item_iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        holder.water_marker_item_icon_im.setTag(path);
        ImageLoader.getInstance().displayImage(Uri.fromFile(new File(path)).toString(), holder.tiny_time_sample_item_iv, options);

        return convertView;
    }

    public void setCollageConfigInfoSampleItemInfoList(ArrayList<CollageConfigInfo.SampleItemInfo> list)
    {
        mList = list;
    }

    class SampleItemInfoHolder
    {
        ImageView tiny_time_sample_item_iv;
        TextView tiny_time_sample_title_tv;
    }
}
